/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utils;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class Encrypt {

    public static String toMD5(String val) {
        String hash = "";
        try {
            MessageDigest mdg = MessageDigest.getInstance("MD5");
            byte[] data = mdg.digest(val.getBytes("UTF-8"));
            for (int i = 0; i < data.length; i++) {
                String hex = Integer.toHexString(0xff & data[i]);
                if (hex.length() == 1) {
                    hash += 0;
                }
                hash += hex;
            }
        } catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) {
            Logger.getLogger(Encrypt.class.getName()).log(Level.SEVERE, null, ex);
        }
        return hash;
    }
    public static void main(String[] args) {
        
    }
}
